package com.qf.flowerlanguage.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.flowerlanguage.entity.Classes;
import com.qf.flowerlanguage.entity.Product;
import com.qf.flowerlanguage.entity.User;
import com.qf.flowerlanguage.service.HomeService;
import com.qf.flowerlanguage.service.ProductService;

import com.qf.flowerlanguage.vo.ProductVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/product")
public class ProductController {
    @Autowired
    private ProductService productService;




    @RequestMapping("/particulars")
    @ResponseBody
    public ProductVo particulars(Integer pid){
        QueryWrapper<Product> productQW = new QueryWrapper<>();
        QueryWrapper<Product> pid1 = productQW.eq("pid", pid);
        Product one = productService.getOne(pid1);
        ProductVo productVo = new ProductVo();
        productVo.setMessage("传如成功");
        productVo.setProduct(one);
        return productVo;

    }
    @RequestMapping("/getAll")
    @ResponseBody
    public ProductVo getAll(Page<Product> page,String cids){
        IPage<Product> all = productService.getAllProductAndClasses(page,cids);
        ProductVo productVo=new ProductVo();
        if (all==null){
            productVo.setMessage("无匹配id");
        }else {
            productVo.setMessage("匹配id成功");
            productVo.setProductList(all.getRecords());
        }
        return productVo;
    }

}
